<div class="dealOrderCodes index">
	<!-- 
	<div class="actions">
		<ul>
			<li>
				<?php
				//echo $html->link(__('Back', true), array("plugin"=>"deals",'controller'=>'deal_orders','action'=>'admin_index',$dealOrder['DealOrder']['deal_id']),array('class'=>'add_button'));
				?>
			</li>
		</ul>
	</div>
	 -->
<?php
$index->setData($codes, 'DealOrderCode');

$index->showFields(array("id",array('deal_order_id'=>__('Order ID')),array('deal_id'=>__('Deal')),array('user_id'=>__('User')),array('deal_code'=>'Code'),array('amount'=>'Amount'),array("transaction_id"=>__("Transaction ID"))));
//$index->sortableFields(array());

$index->addColumn('user_id','showUser');
$index->addColumn('deal_id','showDeal');
$index->addColumn('transaction_id','showTransaction');

function showDeal($record)
{
	$deal = ClassRegistry::getObject('View')->viewVars['dealOrder'];
	return $deal['Deal']['title'];
}

function showUser($record)
{
	$deal = ClassRegistry::getObject('View')->viewVars['dealOrder'];
	return $deal['User']['display_name'];
}

function showTransaction($record)
{
	$deal = ClassRegistry::getObject('View')->viewVars['dealOrder'];
	return $deal['DealOrder']['paymentTransactionId'];
}

function canMarkUsed($model, $record)
{
	if(!$record[$model]['is_used'])
	{
		$action['title'] = __('Mark used');
		$action['url'] = '/admin/deals/deal_order_codes/changeUsedStatus/'.$record[$model]['id'];
		$action['confirmMessage'] = __('Are you sure ?');
		return $action;
	} else {
		return false;
	}
}

$index->setAction(null, null,$this->helpers,false,true,'canMarkUsed');

echo $index->display($codes);
?>
</div>